package com.hxzy.authentication.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.hxzy.authentication.domain.TsVehicleCertification;
import com.hxzy.authentication.mapper.TsVehicleCertificationMapper;
import com.hxzy.authentication.service.TsVehicleCertificationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.DataSourceType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author mingqian.Wu
 * @since 2023-06-23
 */
@Service
@DataSource(DataSourceType.AUTHENTICATION)
public class TsVehicleCertificationServiceImpl extends ServiceImpl<TsVehicleCertificationMapper, TsVehicleCertification> implements TsVehicleCertificationService {

    @Autowired
    private TsVehicleCertificationMapper tsVehicleCertificationMapper;


    @Override
    public TsVehicleCertification getById(Integer authenticationId) {
        return baseMapper.selectById(authenticationId);
    }

    @Override
    public List<TsVehicleCertification> getTs(TsVehicleCertification tsVehicleCertification) {
        QueryWrapper<TsVehicleCertification> wrapper=new QueryWrapper<>();
        wrapper.eq(Objects.nonNull(tsVehicleCertification.getUserName()),"user_name",tsVehicleCertification.getUserName());
        wrapper.eq(Objects.nonNull(tsVehicleCertification.getRegisterPhone()),"register_phone",tsVehicleCertification.getRegisterPhone());
        wrapper.eq(Objects.nonNull(tsVehicleCertification.getLicensePlateNumber()),"license_plate_number",tsVehicleCertification.getLicensePlateNumber());
        wrapper.eq(Objects.nonNull(tsVehicleCertification.getEnergySign()),"energy_sign",tsVehicleCertification.getEnergySign());
        wrapper.eq(Objects.nonNull(tsVehicleCertification.getApplyTime()),"apply_time",tsVehicleCertification.getApplyTime());
        wrapper.eq(Objects.nonNull(tsVehicleCertification.getAuditTime()),"audit_time",tsVehicleCertification.getAuditTime());
        List<TsVehicleCertification> tsVehicleCertifications = tsVehicleCertificationMapper.selectList(wrapper);
        return tsVehicleCertifications;
    }

    @Override
    public List<TsVehicleCertification> getZhuangTai(Integer certificationStatus) {
        QueryWrapper<TsVehicleCertification> wrapper=new QueryWrapper<>();
//        wrapper.eq(Objects.nonNull(certificationStatus),"certification_status",certificationStatus);

        if (certificationStatus!=null){
            wrapper.eq("certification_status", certificationStatus);
        }
        List<TsVehicleCertification> tsVehicleCertifications = tsVehicleCertificationMapper.selectList(wrapper);
        return tsVehicleCertifications;




    }



    @Override
    public List<TsVehicleCertification> gettsVehicle(String licensePlateNumber) {
        QueryWrapper<TsVehicleCertification> wrapper=new QueryWrapper<>();
        if (licensePlateNumber!=null){
            wrapper.eq("license_plate_number",licensePlateNumber);
        }
        List<TsVehicleCertification> tsVehicleCertifications = baseMapper.selectList(wrapper);
        return tsVehicleCertifications;

    }

    @Override
    public AjaxResult updataTtVehicleInformation(TsVehicleCertification licensePlateNumber) {

        UpdateWrapper<TsVehicleCertification> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("license_plate_number",licensePlateNumber.getLicensePlateNumber());
        int update = tsVehicleCertificationMapper.update(licensePlateNumber, updateWrapper);
        if (update!=0){
            return AjaxResult.success("修改成功");
        }
        return AjaxResult.error("修改失败");



    }
}
